<template>
    <div>
        <h1>当前求和为：{{sumResult}}</h1>
        <h3>当前求和更大为：{{bigSumResult}}</h3>
        <h3>我在{{$store.state.school}},学习{{subName}}</h3>
         <select v-model.number="num">
            <option :value="1">1</option>
            <option :value="2">2</option>
            <option :value="3">3</option>
        </select>
        <button @click="add">+</button>
        <button @click="dec">-</button>
        <button @click="addOdd">当前求和为奇数再加</button>
        <button @click="addWait">等一等再加</button>
    </div>
</template>

<script>
    import {mapState} from 'vuex'
     export default {
        name:'count',
        data() {
            return {
                num:1,
            }
        },
        methods: {
            add(){
                // this.$store.dispatch('add',this.num)
                this.$store.commit('ADD',this.num)
            },
            dec(){
                // this.$store.dispatch('dec',this.num)
                this.$store.commit('DEC',this.num)
            },
            addOdd(){
                this.$store.dispatch('addOdd',this.num)
            },
            addWait(){
                this.$store.dispatch('addWait',this.num)
            },
        },
        mounted() {
            // console.log("count",this);
            const x = mapState({sumResult:'sum',schoolName:'school',subName:'subject'});
            console.log(x);
            
        },
        computed: {
            // sumResult(){
            //     return this.$store.state.sum
            // },
            // schoolName(){
            //     return this.$store.state.school
            // },
            // subName(){
            //     return this.$store.state.subject
            // },
            ...mapState({sumResult:'sum',schoolName:'school',subName:'subject'}),
            bigSumResult(){
                return this.$store.getters.moreBig
            }
        },
     }
</script>

<style scoped>
    button {
        margin-left: 10px;
    }
</style>